IF EXISTS (SELECT * FROM sysobjects WHERE type = 'U' AND name = 'EVENT')
BEGIN
    DROP TABLE [dbo].[EVENT]
END

GO

CREATE TABLE [dbo].[EVENT] ( 
	[ID]			INT IDENTITY(1,1) NOT FOR REPLICATION NOT NULL,
    [WHAT]          VARCHAR(64)     NOT NULL,
    [GROUP_ID]      INT,
    [START_TIME]    DATETIME        NOT NULL,
    [END_TIME]      DATETIME        NOT NULL,
	[LAST_TIME]     DATETIME,
    [REPEAT]        VARCHAR(10)     NOT NULL CONSTRAINT [CK_EVENT_REPEAT]
            CHECK NOT FOR REPLICATION (REPEAT IN ('Non', 'Daily', 'Weekly', 'Monthly'))
            DEFAULT 'Non',
    [WHERE]         VARCHAR(64),
    [DESCRIPTION]   VARCHAR(256),
    [MODULE_ID]     INT             NOT NULL,
    [RESULT_TYPE]   VARCHAR(10)     NOT NULL CONSTRAINT [CK_EVENT_RESULT_TYPE]
            CHECK NOT FOR REPLICATION (RESULT_TYPE IN ('Status', 'Pass', 'Mark'))
            DEFAULT 'Status',

    CONSTRAINT [PK_EVENT_ID] PRIMARY KEY CLUSTERED ( 
        [ID] 
    ) ON [PRIMARY],
    
    CONSTRAINT [FK_EVENT_MODULE_ID] FOREIGN KEY ( 
        [MODULE_ID]
    ) REFERENCES [dbo].[EDUCATION_MODULE] (
        [ID]
    )
    
) ON [PRIMARY]
GO